<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha256-Z1K5uhUaJXA7Ll0XrZ/0JhX4lAtZFpT6jkKrEDT0drU=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Muse","darkmode":false,"version":"8.14.0","exturl":false,"sidebar":{"position":"right","display":"hide","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>

    <meta name="description" content="目的从git上自动拉取代码 自动打包编译react项目 自动将打包编译后的文件发送到远程服务器nginx的目录下">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux Centos7 使用Jenkins部署React前端项目自动化">
<meta property="og:url" content="http://example.com/fef9570c.html">
<meta property="og:site_name" content="Tony Liu 的博客">
<meta property="og:description" content="目的从git上自动拉取代码 自动打包编译react项目 自动将打包编译后的文件发送到远程服务器nginx的目录下">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2018-11-13T16:00:00.000Z">
<meta property="article:modified_time" content="2023-01-05T06:27:06.716Z">
<meta property="article:author" content="Tony Liu">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="Jenkins">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://example.com/fef9570c.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://example.com/fef9570c.html","path":"fef9570c.html","title":"Linux Centos7 使用Jenkins部署React前端项目自动化"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Linux Centos7 使用Jenkins部署React前端项目自动化 | Tony Liu 的博客</title>
  






  <script async defer data-website-id="" src=""></script>

  <script defer data-domain="" src=""></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Tony Liu 的博客</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">为所当为 顺其自然</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
  </ul>
</nav>




</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9B%AE%E7%9A%84"><span class="nav-number">1.</span> <span class="nav-text">目的</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C"><span class="nav-number">2.</span> <span class="nav-text">准备工作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BC%80%E5%A7%8B%E6%93%8D%E4%BD%9C"><span class="nav-number">3.</span> <span class="nav-text">开始操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE"><span class="nav-number">3.1.</span> <span class="nav-text">基础配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E4%BB%BB%E5%8A%A1"><span class="nav-number">3.2.</span> <span class="nav-text">创建任务</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E4%BB%BB%E5%8A%A1"><span class="nav-number">3.3.</span> <span class="nav-text">配置任务</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#nginx%E7%9B%AE%E5%BD%95%E9%85%8D%E7%BD%AE"><span class="nav-number">4.</span> <span class="nav-text">nginx目录配置</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Tony Liu</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">4</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/fef9570c.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Tony Liu">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Tony Liu 的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Linux Centos7 使用Jenkins部署React前端项目自动化 | Tony Liu 的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Linux Centos7 使用Jenkins部署React前端项目自动化
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2018-11-14 00:00:00" itemprop="dateCreated datePublished" datetime="2018-11-14T00:00:00+08:00">2018-11-14</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Linux/" itemprop="url" rel="index"><span itemprop="name">Linux</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="目的"><a href="#目的" class="headerlink" title="目的"></a>目的</h2><p>从git上自动拉取代码</p>
<p>自动打包编译react项目</p>
<p>自动将打包编译后的文件发送到远程服务器nginx的目录下</p>
<span id="more"></span>

<h2 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h2><ul>
<li>已有git的代码库</li>
<li>已安装jenkins</li>
<li>已安装nodejs环境</li>
</ul>
<h2 id="开始操作"><a href="#开始操作" class="headerlink" title="开始操作"></a>开始操作</h2><h3 id="基础配置"><a href="#基础配置" class="headerlink" title="基础配置"></a>基础配置</h3><p>为jenkins安装以下两个插件</p>
<ul>
<li><a target="_blank" rel="noopener" href="http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin">NodeJS Plugin</a>：nodejs环境配置</li>
<li><a target="_blank" rel="noopener" href="http://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin">Publish Over SSH</a>：远程控制插件，用于发送文件</li>
</ul>
<p>在jenkins上配置nodejs</p>
<ul>
<li>系统管理-&gt;全局工具配置：找到nodejs进行配置，选择相应的版本，然后勾选自动下载即可</li>
</ul>
<p>在jenkins上配置远程服务器的ssh，也就是我们要把文件发送到这个服务器上</p>
<ul>
<li><p>系统管理-&gt;系统设置：找到Publish over SSH的配置区域</p>
<p>其中<code>Remote Directory</code>填写<code>/</code>,在之后的配置里，直接写全路径就可以了</p>
<p>然后点击<code>test Configuration</code>按钮进行测试连接一下，显示 Success就说明配置成功了</p>
</li>
</ul>
<h3 id="创建任务"><a href="#创建任务" class="headerlink" title="创建任务"></a>创建任务</h3><ul>
<li>点击<code>新建任务</code></li>
<li>输入任务名称、选择<code>构建一个自由风格的软件项目</code></li>
<li>然后进入该任务的配置页进行相关的配置</li>
</ul>
<h3 id="配置任务"><a href="#配置任务" class="headerlink" title="配置任务"></a>配置任务</h3><ul>
<li><p>源码管理：</p>
<p>选择git，输入仓库的地址，如果jenkins中没有git的全局凭证，默认的情况下自己创建一个即可</p>
</li>
<li><p>构建环境：</p>
<p>在这个区域选择构建环境，选择<code>Provide Node &amp; npm bin/ folder to PATH</code>，然后下拉选上之前配置的nodejs的名称</p>
</li>
<li><p>构建：</p>
<p>选择<code>执行shell</code>，输入相关命令，注意：这里的目录是相对于git拉取的根目录下，执行命令的时候注意参考</p>
</li>
<li><p>构建后操作：</p>
<p>选择<code>Send build artifacts over SSH</code>，选择之前配置的服务器</p>
<p><code>Source files</code>：填写要传送的文件，这个目录是相对于jenkins的工作空间目录</p>
<p><code>Remove prefix</code>：移除的目录前缀，如果<code>Source files</code>填写A&#x2F;B&#x2F;C.txt，该处不填写内容，目标服务器就会递归的创建相对应的目录，如果该处填写&#x2F;A&#x2F;B，则目标服务器之将文件传送到指定目录，不进行创建</p>
</li>
<li><p><code>Remote directory</code>：要将文件传送到服务器的那个目录下</p>
</li>
<li><p><code>Exec command</code>：这里填写命令，这些命令会在目标服务器上运行</p>
</li>
</ul>
<h2 id="nginx目录配置"><a href="#nginx目录配置" class="headerlink" title="nginx目录配置"></a>nginx目录配置</h2><p>如果更改了nginx配置中的root，需要注意这个文件夹要拥有nginx用户的所有权限，配置文件中有user的配置，有两种途径</p>
<ul>
<li>更改这个文件夹的权限为nginx用户</li>
<li>将配置文件的user更改到相对应的用户</li>
</ul>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Linux/" rel="tag"># Linux</a>
              <a href="/tags/Jenkins/" rel="tag"># Jenkins</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/4ecb35f5.html" rel="prev" title="Python itchat个人微信账号接口定时发送群消息">
                  <i class="fa fa-chevron-left"></i> Python itchat个人微信账号接口定时发送群消息
                </a>
            </div>
            <div class="post-nav-item">
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2012 – 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tony Liu</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  




  





</body>
</html>
